`include "Mult16_Simple.v"

module Mult16_tb;
    reg [15:0] a, b;
    wire [31:0] product;
    
    Mult16_Simple mult(a, b, product);
    
    // 显示测试结果的任务
    task display_test;
        input [15:0] val_a, val_b;
        input [31:0] expected;
        begin
            a = val_a;
            b = val_b;
            #10;
            $display("Test: %d * %d = %d (expected: %d) %s", 
                     $signed(a), $signed(b), $signed(product), $signed(expected),
                     ($signed(product) == $signed(expected)) ? "PASS" : "FAIL");
        end
    endtask
    
    initial begin
        $display("=== 16位有符号乘法器测试 ===");
        
        // 测试用例1: 正数 × 正数
        display_test(16'd5, 16'd3, 32'd15);
        
        // 测试用例2: 正数 × 负数
        display_test(16'd5, 16'hFFFD, 32'hFFFFFFF1); // 5 * (-3) = -15
        
        // 测试用例3: 负数 × 正数
        display_test(16'hFFFB, 16'd3, 32'hFFFFFFF1); // (-5) * 3 = -15
        
        // 测试用例4: 负数 × 负数
        display_test(16'hFFFB, 16'hFFFD, 32'd15); // (-5) * (-3) = 15
        
        // 测试用例5: 乘以0
        display_test(16'd100, 16'd0, 32'd0);
        display_test(16'd0, 16'd100, 32'd0);
        
        // 测试用例6: 乘以1
        display_test(16'd123, 16'd1, 32'd123);
        display_test(16'hFF85, 16'd1, 32'hFFFFFF85); // -123 * 1 = -123
        
        // 测试用例7: 乘以-1
        display_test(16'd123, 16'hFFFF, 32'hFFFFFF85); // 123 * (-1) = -123
        display_test(16'hFF85, 16'hFFFF, 32'd123); // (-123) * (-1) = 123
        
        // 测试用例8: 较大的数
        display_test(16'd100, 16'd100, 32'd10000);
        display_test(16'd255, 16'd255, 32'd65025);
        
        // 测试用例9: 边界情况
        display_test(16'h7FFF, 16'd2, 32'hFFFE); // 32767 * 2 = 65534
        display_test(16'h8000, 16'd1, 32'hFFFF8000); // -32768 * 1 = -32768
        
        // 测试用例10: 可能溢出的大数相乘
        display_test(16'h7FFF, 16'h7FFF, 32'h3FFF0001); // 32767 * 32767
        
        $display("=== 测试完成 ===");
        $finish;
    end
    
endmodule
